﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.Data;

public partial class Admin_LocationFeesMaster : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetData();
            //Session["UserID"] = Guid.NewGuid();
        }
    }

    private void GetData()
    {
        /*if (hdnInput.Value == "search")
        {
            DataSet objDs = new DataSet();
            objDs = GetDataSet();
            DataView objDv = new DataView();
            objDv = objDs.Tables[0].DefaultView;
            objDv.RowFilter = "CountryName  LIKE '*" + txtActivityTypeName.Text.Trim() + "*'";
            gvLanguage.DataSource = objDv;
        }
        else
        {
            gvLanguage.DataSource = GetDataSet();
        }
        gvLanguage.DataBind();*/


        gvLocationFees.DataSource = GetDataSet();
        gvLocationFees.DataBind();
        gvLocationFees.Visible = true;
    }

    protected void btnClearLocFees_Click(object sender, EventArgs e)
    {
        ClearData();
    }

    protected void btnAddLocFees_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //lblMessage.Text = "";
            if (txtLocationFeesId.Text == "")
            {

                LocationFeesMasterBAL objLMBal;
                LocationFeesMasterBO objLMBO;
                //Guid gudUserID = new Guid(Convert.ToString(Session["UserID"]));
                //int intLgid = Convert.ToInt16(Request.QueryString["lgid"]);

                objLMBal = new LocationFeesMasterBAL();
                objLMBO = new LocationFeesMasterBO();

                objLMBO.SetMethod = "INSERT";
                objLMBO.intLocationFeesId = 0;
                objLMBO.strLocation = txtLocation.Text.Trim();
                //objLMBO.ActivityCode = txtActivityTypeCode.Text.Trim();
                objLMBO.dblFees = Convert.ToDouble(txtFees.Text);

                string strReturnValue = (string)objLMBal.SetLocationFeesMaster(objLMBO.SetMethod, objLMBO.intLocationFeesId, objLMBO.strLocation, objLMBO.dblFees); // .SetCountryMaster(objLMBO.SetMethod, objLMBO.CountryID, objLMBO.CountryName, objLMBO.RegionID, objLMBO.CountryTelCode, objLMBO.CountryCode, objLMBO.CreatedBy, objLMBO.@ModifyBy, objLMBO.ModifyDate, objLMBO.IsActive);
                if (strReturnValue == "SUCCESS")
                {
                    ClearData();
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Record has been save succesfully.');", true);
                    //lblMessage.Text = "Record has been save succesfully.";
                    //lblMessage.ForeColor = System.Drawing.Color.Green;
                    GetData();

                }
                else if (strReturnValue == "EXIST")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Country type already exists.');", true);
                    //lblMessage.Text = "Country type already exists."; //EnrollResources.GetMessage(Message.InsertMessage); //  
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error while saving record.');", true);
                    //lblMessage.Text = "Error while saving record."; //EnrollResources.GetMessage(Message.FailedMessage); // 
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            else
            {

                LocationFeesMasterBAL objLMBal;
                LocationFeesMasterBO objLMBO;
                //Guid gudUserID = new Guid(Convert.ToString(Session["UserID"]));
                //int intLgid = Convert.ToInt16(Request.QueryString["lgid"]);

                objLMBal = new LocationFeesMasterBAL();
                objLMBO = new LocationFeesMasterBO();

                objLMBO.SetMethod = "UPDATE";
                objLMBO.intLocationFeesId = Convert.ToInt16(txtLocationFeesId.Text);
                objLMBO.strLocation = txtLocation.Text.Trim();
                //objLMBO.ActivityCode = txtActivityTypeCode.Text.Trim();
                objLMBO.dblFees = Convert.ToDouble(txtFees.Text);

                string strReturnValue = (string)objLMBal.SetLocationFeesMaster(objLMBO.SetMethod, objLMBO.intLocationFeesId, objLMBO.strLocation, objLMBO.dblFees); // .SetCountryMaster(objLMBO.SetMethod, objLMBO.CountryID, objLMBO.CountryName, objLMBO.RegionID, objLMBO.CountryTelCode, objLMBO.CountryCode, objLMBO.CreatedBy, objLMBO.@ModifyBy, objLMBO.ModifyDate, objLMBO.IsActive);
                if (strReturnValue == "SUCCESS")
                {
                    ClearData();
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Record has been save succesfully.');", true);
                    //lblMessage.Text = "Record has been save succesfully.";
                    //lblMessage.ForeColor = System.Drawing.Color.Green;
                    GetData();

                }
                else if (strReturnValue == "EXIST")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Country type already exists.');", true);
                    //lblMessage.Text = "Country type already exists."; //EnrollResources.GetMessage(Message.InsertMessage); //  
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error while saving record.');", true);
                    //lblMessage.Text = "Error while saving record."; //EnrollResources.GetMessage(Message.FailedMessage); // 
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            
        }
    }
    private void ClearData()
    {

        txtLocation.Text = string.Empty;
        //txtActivityTypeCode.Text = string.Empty;
        txtFees.Text = string.Empty;
        txtLocationFeesId.Text = string.Empty;
        //lblMessage.Text = string.Empty;
        btnAddLocFees.Text = "Add";
    }


    private DataSet GetDataSet()
    {

        DataSet objDs = null;
        try
        {
            objDs = new LocationFeesMasterBAL().GetLocationFeesMaster();
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;

    }

    protected void gvLocationFees_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        LinkButton lnkView = (LinkButton)e.CommandSource;
        //Int16 intLocationFeesId = Convert.ToInt16( lnkView.CommandArgument);
        string[] arg = new string[3];
        arg = e.CommandArgument.ToString().Split(';');
        /*Int16 intLocationFeesId = Convert.ToInt16(arg[0]);
        string strLocation = arg[1];
        double dblFees = Convert.ToDouble(arg[2]);*/
        if (e.CommandName=="DELETE1")
        {
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Deleting record. ');", true);
            deleteLocationFees(Convert.ToInt16(arg[0]));
        }
        else if (e.CommandName == "EDIT1")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Edit record. ');", true);
            txtLocationFeesId.Text = arg[0];
            txtLocation.Text = arg[1];
            txtFees.Text = arg[2];
            btnAddLocFees.Text = "Update";
        }
    }

    protected void lnkEdit_Click(object sender, EventArgs e)
    {

    }

    void deleteLocationFees(Int16 intLocationFeesId)
    {
        
        if (intLocationFeesId != 0 )
        {
            LocationFeesMasterBAL objLMBal;
            LocationFeesMasterBO objLMBO;
            //Guid gudUserID = new Guid(Convert.ToString(Session["UserID"]));
            //int intLgid = Convert.ToInt16(Request.QueryString["lgid"]);

            objLMBal = new LocationFeesMasterBAL();
            objLMBO = new LocationFeesMasterBO();

            objLMBO.SetMethod = "DELETE";
            objLMBO.intLocationFeesId = intLocationFeesId;
            

            string strReturnValue = (string)objLMBal.SetLocationFeesMaster(objLMBO.SetMethod, objLMBO.intLocationFeesId, objLMBO.strLocation, objLMBO.dblFees); // .SetCountryMaster(objLMBO.SetMethod, objLMBO.CountryID, objLMBO.CountryName, objLMBO.RegionID, objLMBO.CountryTelCode, objLMBO.CountryCode, objLMBO.CreatedBy, objLMBO.@ModifyBy, objLMBO.ModifyDate, objLMBO.IsActive);
            if (strReturnValue == "SUCCESS")
            {
                ClearData();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Record has been delete succesfully.');", true);
                //lblMessage.Text = "Record has been save succesfully.";
                //lblMessage.ForeColor = System.Drawing.Color.Green;
                GetData();

            }
            else if (strReturnValue == "EXIST")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Country type already exists.');", true);
                //lblMessage.Text = "Country type already exists."; //EnrollResources.GetMessage(Message.InsertMessage); //  
                //lblMessage.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error while saving record.');", true);
                //lblMessage.Text = "Error while saving record."; //EnrollResources.GetMessage(Message.FailedMessage); // 
                //lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}
    